package com.wyh.controller.g3controller;


import com.wyh.common.enums.ResultCodeEnum;
import com.wyh.common.result.Result;
import com.wyh.domain.dto.g3dto.G3OrganizationDto;
import com.wyh.domain.po.g3po.ChargeProjectRate;
import com.wyh.domain.vo.g3vo.*;
import com.wyh.service.g3service.IOrganizationService;
import com.wyh.service.g3service.IProjectService;
import com.wyh.utils.g3utils.ProjectUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 组织表 前端控制器
 * </p>
 *
 * @author 唐书亮
 * @since 2024-05-21
 */
@RestController
@RequestMapping("/organization")
@Api(tags = "管理看板查询")
@Component("g3OrganizationController")
public class OrganizationController {
    @Autowired
    private IOrganizationService organizationService;
    @Autowired
    private IProjectService projectService;

    @ApiOperation("查询组织")
    @GetMapping("selectOrganization")
    public Result<G3OrganizationVo> selectAllOrByName(@ApiParam(value = "组织名,不传递时默认查询全部") @RequestParam(value = "name", required = false) String name) {
        G3OrganizationVo g3OrganizationVo = organizationService.selectAllOrByName(name);
        //将查询结果返回
        return Result.success(g3OrganizationVo);
    }

    @ApiOperation("面板查询")
    @PostMapping("project")
    public Result<PropertyManagementVO> selectProject(@ApiParam("组织信息")@RequestBody G3OrganizationDto g3OrganizationDto) {
        if (g3OrganizationDto == null) {
            return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
        }
        PropertyManagementVO propertyManagementVO = projectService.selectProject(g3OrganizationDto);

        return Result.success(propertyManagementVO);
    }

    @ApiOperation("收费看板")
    @PostMapping("chargeType")
    public Result<ChargeTypeVo> selectChargeType(@ApiParam("组织信息") @RequestBody G3OrganizationDto g3OrganizationDto) {
        ChargeTypeVo chargeTypeVo = projectService.selectChargeType(g3OrganizationDto);
        if (g3OrganizationDto == null) {
            return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
        }
        return Result.success(chargeTypeVo);
    }

    @ApiOperation("收费率楼盘排名")
    @PostMapping("chargeRate")
    public Result<ChargeRateVO> selectChargeRate(@ApiParam("组织信息")@RequestBody G3OrganizationDto g3OrganizationDto) {
        // 将时间封装进去
        ProjectUtils.encapsulationTime(g3OrganizationDto);
        List<ChargeProjectRate> chargeProjectRates = projectService.selectChargeRate(g3OrganizationDto);
        ChargeRateVO chargeRateVO = new ChargeRateVO();
        chargeRateVO.setChargeProjectRateList(chargeProjectRates);
        return Result.success(chargeRateVO);
    }

    @ApiOperation("收费率统计")
    @PostMapping("allChargeRate")
    public Result<AllChargeRateVO> selectAllChargeRate(@ApiParam("组织信息")@RequestBody G3OrganizationDto g3OrganizationDto) {
        if (ProjectUtils.isPartEmpty(g3OrganizationDto)){
            return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
        }
        AllChargeRateVO allChargeRateVO = projectService.selectAllChargeRate(g3OrganizationDto);
        if (allChargeRateVO == null){
            return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
        }
        return Result.success(allChargeRateVO);

    }
}
